home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 2: CDPD 1 / Almathera Ten on Ten - Disc 2: CDPD 1.iso / pd / 351-375 / 351 / pdc / pdcsrc.lzh / PDC / Expr.c < prev    next >
C/C++ Source or Header  |  1990-04-06  |  41KB  |  1,529 lines

  1.  
  2. /* PDC Compiler - A Freely Distributable C Compiler for the Amiga
  3.  *                Based upon prior work by Matthew Brandt and Jeff Lydiatt.
  4.  *
  5.  * PDC Compiler release 3.3 Copyright (C) 1989 Paul Petersen and Lionel Hummel.
  6.  * PDC Software Distribution (C) 1989 Lionel Hummel and Paul Petersen.
  7.  *
  8.  * This code is freely redistributable upon the conditions that this 
  9.  * notice remains intact and that modified versions of this file not be 
  10.  * distributed as part of the PDC Software Distribution without the express
  11.  * consent of the copyright holders.
  12.  *
  13.  *------------------------------------------------------------------
  14.  *
  15.  * $Log:    Expr.c,v $
  16.  * Revision 3.33  90/04/04  23:19:19  lionel
  17.  * Added recognition of unsigned *, /, and % operations.
  18.  * 
  19.  * Revision 3.32  90/02/03  16:23:29  lionel
  20.  * None
  21.  * 
  22.  *------------------------------------------------------------------
  23.  */
  24.  
  25. /*
  26.  * Expr.c
  27.  * 
  28.  * expression evaluation
  29.  * 
  30.  * This set of routines builds a parse tree for an expression. no code is
  31.  * generated for the expressions during the build, this is the job of the
  32.  * codegen module. for most purposes expression() is the routine to call. it
  33.  * will allow all of the C operators. for the case where the comma operator
  34.  * is not valid (function parameters for instance) call exprnc().
  35.  * 
  36.  * Each of the routines returns a pointer to a describing type structure. each
  37.  * routine also takes one parameter which is a pointer to an expression node
  38.  * by reference (address of pointer). the completed expression is returned in
  39.  * this pointer. all routines return either a pointer to a valid type or NULL
  40.  * if the hierarchy of the next operator is too low or the next symbol is not
  41.  * part of an expression.
  42.  */
  43.  
  44. /* 890926 (LDH) Removed forcefit() for && and || ops.  It generates irrelevant
  45.  *              code.
  46.  */
  47.  
  48. #include    <stdio.h>
  49. #include    "C.h"
  50. #include    "Expr.h"
  51. #include    "Gen.h"
  52. #include    "Cglbdec.h"
  53.  
  54. TYP             stdint = {bt_long, 0, 4, {0, 0}, 0, "int"};
  55. TYP             stdunsigned = {bt_unsigned, 0, 4, {0, 0}, 0, "unsigned"};
  56. TYP             stdchar = {bt_char, 0, 1, {0, 0}, 0, "char"};
  57. TYP             stdshort = {bt_short, 0, 2, {0, 0}, 0, "short"};
  58. TYP             stdstring = {bt_pointer, 1, 4, {0, 0}, &stdchar, "string"};
  59. TYP             stdfunc = {bt_func, 1, 0, {0, 0}, &stdint, "func"};
  60. TYP             stdfloat = {bt_float, 0, 4, {0, 0}, 0, "float"};
  61. TYP             stddouble = {bt_double, 0, 8, {0, 0}, 0, "double"};
  62.  
  63. extern TYP     *head;       /* shared with decl */
  64. extern TYP     *istypedef();
  65. extern TYP     *maketype();
  66. extern SYM     *gsearch();
  67. extern SYM     *search();
  68. extern char    *litlate();
  69. extern long     stringlit();
  70. extern long     floatlit();
  71. extern int      dodefined();
  72. extern char    *xalloc();
  73. extern int      oneline;
  74.  
  75. TYP            *asforcefit();   /* Forward declaration */
  76. TYP            *forcefit();
  77.  
  78. TYP            *expression();   /* forward declaration */
  79. TYP            *exprnc();   /* forward declaration */
  80. TYP            *unary();    /* forward declaration */
  81.  
  82. struct enode   *
  83. makenode(nt, v1, v2)
  84.  
  85. /*
  86.  * build an expression node with a node type of nt and values v1 and v2.
  87.  */
  88.     enum e_node     nt;
  89.     struct enode   *v1, *v2;
  90. {
  91.     struct enode   *ep;
  92.  
  93.     ep = (struct enode *) xalloc(sizeof(struct enode));
  94.     ep->nodetype = nt;
  95.     ep->size = 0;
  96.     ep->constflag = 0;
  97.     ep->signedflag = 1;
  98.     ep->v.p[0] = v1;
  99.     ep->v.p[1] = v2;
  100.     return ep;
  101. }
  102.  
  103. int
  104. equal_types(tp1, tp2)
  105.     TYP            *tp1, *tp2;
  106. {
  107.     if (tp1 == tp2)
  108.         return (TRUE);
  109.  
  110.     if (tp1 != NULL && tp2 != NULL) 
  111.         if (tp1->type == tp2->type) 
  112.             if (equal_types(tp1->btp, tp2->btp)) 
  113.                 return (TRUE);
  114.     return (FALSE);
  115. }
  116.  
  117.  
  118. TYP            *
  119. deref(node, tp)
  120.  
  121. /*
  122.  * build the proper dereference operation for a node using the type pointer
  123.  * tp.
  124.  */
  125.     struct enode  **node;
  126.     TYP            *tp;
  127. {
  128.     struct enode   *ep1;
  129.  
  130.     if (node == NULL || tp == NULL) {
  131.         fprintf( stderr, "DIAG -- NULL argument to deref.\n" );
  132.         return (NULL);
  133.     }
  134.  
  135.     switch (tp->type) {
  136.     case bt_char:
  137.         *node = makenode(en_b_ref, *node, NULL);
  138.         tp = &stdchar;
  139.         break;
  140.     case bt_uchar:
  141.         (*node)->signedflag = 0;
  142.         *node = makenode(en_ub_ref, *node, NULL);
  143.         (*node)->signedflag = 0;
  144.         break;
  145.     case bt_short:
  146.     case bt_enum:
  147.         *node = makenode(en_w_ref, *node, NULL);
  148.         tp = &stdshort;
  149.         break;
  150.     case bt_ushort:
  151.         (*node)->signedflag = 0;
  152.         *node = makenode(en_uw_ref, *node, NULL);
  153.         (*node)->signedflag = 0;
  154.         break;
  155.     case bt_long:
  156.     case bt_pointer:
  157.         *node = makenode(en_l_ref, *node, NULL);
  158.         break;
  159.     case bt_unsigned:
  160.         (*node)->signedflag = 0;
  161.         *node = makenode(en_ul_ref, *node, NULL);
  162.         (*node)->signedflag = 0;
  163.         tp = &stdunsigned;
  164.         break;
  165.     case bt_struct:
  166.     case bt_union:
  167.         ep1 = makenode(en_icon, (long) tp->size, NULL);
  168.         *node = makenode(en_m_ref, *node, ep1);
  169.         break;
  170.     case bt_float:
  171.         *node = makenode(en_f_ref, *node, NULL);
  172.         tp = &stdfloat;
  173.         break;
  174.     case bt_double:
  175.         *node = makenode(en_d_ref, *node, NULL);
  176.         tp = &stddouble;
  177.         break;
  178.     default:
  179.         error(ERR_DEREF, NULL);
  180.         break;
  181.     }
  182.     return tp;
  183. }
  184.  
  185. TYP            *
  186. nameref(node)
  187.  
  188. /*
  189.  * nameref will build an expression tree that references an identifier. if
  190.  * the identifier is not in the global or local symbol table then a
  191.  * look-ahead to the next character is done and if it indicates a function
  192.  * call the identifier is coerced to an external function name. non-value
  193.  * references generate an additional level of indirection.
  194.  */
  195.     struct enode  **node;
  196. {
  197.     SYM            *sp;
  198.     TYP            *tp;
  199.  
  200.     sp = gsearch(lastid);
  201.  
  202.     if (sp == NULL) {
  203.         ++global_flag;
  204.         sp = (SYM *) xalloc(sizeof(SYM));
  205.         sp->tp = maketype ( bt_func, 0 );
  206.         sp->tp->btp = &stdint;
  207.         sp->tp->val_flag = 1;
  208.         sp->name = litlate(lastid);
  209.         sp->storage_class = sc_external;
  210.         sp->value.i = 1;                    /* External is referenced */
  211.         --global_flag;
  212.  
  213.         getsym();
  214.         /*
  215.          * Declare unknown functions as extern int func()
  216.          */
  217.  
  218.         if (lastst == openpa) {
  219.             insert(sp, &gsyms);
  220.             tp = &stdfunc;
  221.             *node = makenode(en_nacon, sp->name, NULL);
  222.             (*node)->constflag = 1;
  223.         }
  224.         else {
  225.             if (oneline) {      /* Preprocessor kludge */
  226.                 tp = &stdint;
  227.                 *node = makenode(en_icon, 0, NULL );
  228.                 (*node)->constflag = 1;
  229.             }
  230.             else {
  231.                 tp = &stdint;
  232.                 ++global_flag;
  233.                 sp = (SYM *) xalloc(sizeof(SYM));
  234.                 sp->tp = tp;
  235.                 sp->name = litlate(lastid);
  236.                 sp->storage_class = sc_external;
  237.                 sp->value.i = 1;                    /* External is referenced */
  238.                 --global_flag;
  239.                 error(ERR_UNDEFINED, lastid );
  240.                 insert(sp, &gsyms);
  241.                 *node = makenode(en_nacon, sp->name, NULL);
  242.                 (*node)->constflag = 1;
  243.             }
  244.         }
  245.     }
  246.     else {
  247.         if ((tp = sp->tp) == NULL) {
  248.             error(ERR_UNDEFINED, "untyped identifier" );
  249.             return NULL;    /* guard against untyped entries */
  250.         }
  251.         switch (sp->storage_class) {
  252.         case sc_static:
  253.             if (tp->type != bt_func && tp->type != bt_ifunc) 
  254.                 *node = makenode(en_labcon, sp->value.i, NULL);
  255.             else 
  256.                 *node = makenode(en_nacon, sp->name, NULL);
  257.             (*node)->constflag = 1;
  258.             break;
  259.         case sc_external:
  260.             sp->value.i = 1;    /* Referenced    */
  261.             /* FALL-THROUGH */
  262.         case sc_global:
  263.             *node = makenode(en_nacon, sp->name, NULL);
  264.             (*node)->constflag = 1;
  265.             break;
  266.         case sc_const:
  267.             *node = makenode(en_icon, sp->value.i, NULL);
  268.             (*node)->constflag = 1;
  269.             break;
  270.         default:    /* auto and any errors */
  271.             if (sp->storage_class != sc_auto)
  272.                 error(ERR_ILLCLASS, NULL);
  273.             *node = makenode(en_autocon, sp->value.i, NULL);
  274.             break;
  275.         }
  276.         if (tp->val_flag == 0)
  277.             tp = deref(node, tp);
  278.         getsym();
  279.     }
  280.     return tp;
  281. }
  282.  
  283. struct enode   *
  284. parmlist(sp)
  285.     SYM            *sp;
  286.  
  287. /*
  288.  * parmlist will build a list of parameter expressions in a function call and
  289.  * return a pointer to the last expression parsed. since parameters are
  290.  * generally pushed from right to left we get just what we asked for...
  291.  */
  292. {
  293.     int             parmsize;
  294.     struct enode   *ep1, *ep2, *ep3;
  295.     enum e_node     etp;
  296.     TYP            *tp1, *tp2;
  297.     SYM            *sp1;
  298.  
  299.     ep1 = ep2 = ep3 = NULL;
  300.     sp1 = NULL;
  301.     tp1 = tp2 = NULL;
  302.  
  303.     parmsize = 0;
  304.  
  305.     if (sp != NULL && sp->tp != NULL)
  306.         sp1 = sp->tp->lst.head;
  307.  
  308.     while (lastst != closepa) {
  309.         tp1 = exprnc(&ep2); /* evaluate a parameter                         */
  310.  
  311.         if (sp1 != NULL)/* Get the prototype description        */
  312.             tp2 = sp1->tp;
  313.  
  314.         if (tp1 != NULL) {
  315.             if (tp2 != NULL) {
  316.                 if (!equal_types(tp1, tp2))
  317.                     error(ERR_PROTO, NULL);
  318.             }
  319. /* TODO
  320. If assigning prototypes based on prior usage, duplicate this type and assign 
  321. it to sp1->tp.
  322. */
  323.             switch (ep2->nodetype) {
  324.             case en_b_ref:
  325.                 ep2 = makenode(en_cbl, ep2, NULL);
  326.                 parmsize += 4;
  327.                 break;
  328.             case en_ub_ref:
  329.                 ep2 = makenode(en_cbl, ep2, NULL);
  330.                 ep2->signedflag = 0;
  331.                 parmsize += 4;
  332.                 break;
  333.             case en_w_ref:
  334.                 ep2 = makenode(en_cwl, ep2, NULL);
  335.                 parmsize += 4;
  336.                 break;
  337.             case en_uw_ref:
  338.                 ep2 = makenode(en_cwl, ep2, NULL);
  339.                 ep2->signedflag = 0;
  340.                 parmsize += 4;
  341.                 break;
  342.             case en_f_ref:
  343.                 ep2 = makenode(en_cfd, ep2, NULL);
  344.                 parmsize += 8;
  345.                 break;
  346.             case en_d_ref:
  347.                 parmsize += 8;
  348.                 break;
  349.             default:
  350.                 parmsize += 4;
  351.                 break;
  352.             }
  353.         }
  354.         ep1 = makenode(en_void, ep2, ep1);
  355.         if (ep2)
  356.             etp = ep2->nodetype;
  357.         else
  358.             etp = en_void;
  359.         ep3 = makenode(etp, NULL, ep3);
  360.  
  361.         if (lastst != comma)
  362.             break;
  363.  
  364.         getsym();
  365.  
  366.         if (sp1 != NULL)/* Advance to the next prototype variable */
  367.             sp1 = sp1->next;
  368.     }
  369.     ep1 = makenode(en_info, ep1, ep3);
  370.  
  371.     if (parmsize > maxparmsize)
  372.         maxparmsize = parmsize;
  373.  
  374.     return ep1;
  375. }
  376.  
  377. int
  378. castbegin(st)
  379.  
  380. /*
  381.  * return 1 if st in set of [ kw_char, kw_short, kw_long, kw_int, kw_float,
  382.  * kw_double, kw_struct, kw_union, kw_enum ]
  383.  */
  384.     enum e_sym      st;
  385. {
  386.     TYP            *tp;
  387.  
  388.     tp = istypedef(NULL);
  389.  
  390.     return (tp != NULL) ||
  391.         st == kw_char || st == kw_short || st == kw_int ||
  392.         st == kw_long || st == kw_float || st == kw_double ||
  393.         st == kw_enum || st == kw_struct || st == kw_union ||
  394.         st == kw_void || st == kw_unsigned;
  395. }
  396.  
  397. TYP            *
  398. primary(node)
  399.  
  400. /*
  401.  * primary will parse a primary expression and set the node pointer returning
  402.  * the type of the expression parsed. primary expressions are any of: id
  403.  * constant string ( expression ) primary[ expression ] primary.id
  404.  * primary->id primary( parameter list )
  405.  */
  406.     struct enode  **node;
  407. {
  408.     int             index;
  409.     struct enode   *pnode, *qnode, *rnode;
  410.     SYM            *sp, *sp2;
  411.     TYP            *tptr, *tp, *tp2;
  412.  
  413.     switch (lastst) {
  414.     case id:
  415.         tptr = nameref(&pnode);
  416.         break;
  417.     case iconst:
  418.         tptr = &stdint;
  419.         pnode = makenode(en_icon, (long) ival, NULL);
  420.         pnode->constflag = 1;
  421.         getsym();
  422.         break;
  423.     case cconst:
  424.         tptr = &stdint;
  425.         pnode = makenode(en_icon, (long) ival, NULL);
  426.         pnode->constflag = 1;
  427.         getsym();
  428.         break;
  429.     case sconst:
  430.         tptr = &stdstring;
  431.         index = stringlit(laststr);
  432.         pnode = makenode(en_labcon, index, NULL);
  433.         pnode->constflag = 1;
  434.         getsym();
  435.         while (lastst == sconst) {
  436.             stringconcat(index, laststr);
  437.             getsym();
  438.         }
  439.         break;
  440.     case rconst:
  441.         tptr = &stddouble;
  442.         pnode = makenode(en_labcon, floatlit(rval), NULL);
  443.         tptr = deref(&pnode, tptr);
  444.         getsym();
  445.         break;
  446.     case openpa:
  447.         getsym();
  448.         if (!castbegin(lastst)) {
  449.             tptr = expression(&pnode);
  450.             needpunc(closepa);
  451.         }
  452.         else {      /* cast operator */
  453.             decl(NULL); /* do cast declaration */
  454.             decl1();
  455.             tptr = head;
  456.             needpunc(closepa);
  457.             if ((tp = unary(&pnode)) != NULL)
  458.                 tptr = asforcefit(NULL, tptr, &pnode, tp);
  459.             else {
  460.                 error(ERR_IDEXPECT, NULL);
  461.                 tptr = NULL;
  462.             }
  463.         }
  464.         break;
  465.     default:
  466.         return NULL;
  467.     }
  468.  
  469.     if (tptr == NULL) {
  470.         return (NULL);
  471.     }
  472.  
  473.     for (;;) {
  474.         switch (lastst) {
  475.         case openbr:    /* build a subscript reference */
  476.             getsym();
  477.             tp = expression(&rnode);
  478.  
  479.             if (tptr->type != bt_pointer) {
  480.                 if (tp->type != bt_pointer) {
  481.                     error(ERR_NOPOINTER, NULL);
  482.                     break;
  483.                 }
  484.                 qnode = pnode;
  485.                 pnode = rnode;
  486.                 rnode = qnode;
  487.  
  488.                 tp2 = tptr;
  489.                 tptr = tp;
  490.                 tp = tp2;
  491.             }
  492.  
  493.             tptr = tptr->btp;
  494.  
  495.             if (rnode == NULL) {
  496.                 error(ERR_SYNTAX, NULL);
  497.                 break;
  498.             }
  499.  
  500.             /*
  501.              * we could check the type of the expression here...
  502.              */
  503.  
  504.             if (tptr->size == 0)
  505.                 qnode = rnode;
  506.             else {
  507.                 qnode = makenode(en_icon, (long) (tptr->size), NULL);
  508.                 qnode->constflag = 1;
  509.                 qnode = makenode(en_mul, qnode, rnode);
  510.                 qnode->constflag = rnode->constflag && qnode->v.p[0]->constflag;
  511.             }
  512.             pnode = makenode(en_add, pnode, qnode);
  513.             pnode->constflag = qnode->constflag && pnode->v.p[1]->constflag;
  514.             if (tptr->val_flag == 0)
  515.                 tptr = deref(&pnode, tptr);
  516.             needpunc(closebr);
  517.             break;
  518.         case pointsto:
  519.             if (tptr->type != bt_pointer)
  520.                 error(ERR_NOPOINTER, NULL);
  521.             else
  522.                 tptr = tptr->btp;
  523.             if (tptr->val_flag == 0)
  524.                 pnode = makenode(en_l_ref, pnode, NULL);
  525.  
  526.             /*
  527.              * fall through to dot operation
  528.              */
  529.         case dot:
  530.             getsym();   /* past -> or . */
  531.             if (lastst != id)
  532.                 error(ERR_IDEXPECT, NULL);
  533.             else {
  534.                 sp = search(lastid, tptr->lst.head);
  535.                 if (sp == NULL)
  536.                     error(ERR_NOMEMBER, NULL);
  537.                 else {
  538.                     tptr = sp->tp;
  539.                     qnode = makenode(en_icon, (long) (sp->value.i), NULL);
  540.                     qnode->constflag = 1;
  541.                     pnode = makenode(en_add, pnode, qnode);
  542.                     pnode->constflag = pnode->v.p[0]->constflag;
  543.                     if (tptr->val_flag == 0)
  544.                         tptr = deref(&pnode, tptr);
  545.                 }
  546.                 getsym();   /* past id */
  547.             }
  548.             break;
  549.         case openpa:    /* function reference */
  550.             getsym();
  551.             if (tptr->type != bt_func && tptr->type != bt_ifunc)
  552.                 error(ERR_NOFUNC, NULL);
  553.             else
  554.                 tptr = tptr->btp;
  555.  
  556.             if (pnode->nodetype != en_nacon)
  557.                 sp = NULL;
  558.             else {
  559.                 sp = gsearch(pnode->v.sp);
  560.                 if (strncmp( pnode->v.sp, "__LIBCALL_", 10) == 0) {
  561.                     sp2 = gsearch(&pnode->v.sp[10]);
  562.                     if (sp2 != NULL && sp2->tp->lst.head != NULL)
  563.                         sp->tp->lst = sp2->tp->lst;
  564.                 }
  565.             }
  566.  
  567.             pnode = makenode(en_fcall, pnode, parmlist(sp));
  568.             pnode->size = tptr->size;
  569.             needpunc(closepa);
  570.             break;
  571.         default:
  572.             goto fini;
  573.         }
  574.     }
  575. fini:
  576.     *node = pnode;
  577.     return tptr;
  578. }
  579.  
  580. int
  581. lvalue(node)
  582.  
  583. /*
  584.  * this function returns true if the node passed is an lvalue. this can be
  585.  * qualified by the fact that an lvalue must have one of the dereference
  586.  * operators as it's top node.
  587.  */
  588.     struct enode   *node;
  589. {
  590.     switch (node->nodetype) {
  591.     case en_b_ref:
  592.     case en_ub_ref:
  593.     case en_w_ref:
  594.     case en_uw_ref:
  595.     case en_l_ref:
  596.     case en_ul_ref:
  597.     case en_m_ref:
  598.     case en_f_ref:
  599.     case en_d_ref:
  600.         return TRUE;
  601.     case en_cbl:
  602.     case en_cwl:
  603.     case en_cbw:
  604.     case en_clf:
  605.     case en_cld:
  606.     case en_cfl:
  607.     case en_cdl:
  608.     case en_cfd:
  609.         return lvalue(node->v.p[0]);
  610.     }
  611.     return FALSE;
  612. }
  613.  
  614. TYP            *
  615. unary(node)
  616.  
  617. /*
  618.  * unary evaluates unary expressions and returns the type of the expression
  619.  * evaluated. unary expressions are any of:
  620.  * 
  621.  * primary primary++ primary-- !unary ~unary ++unary --unary -unary *unary
  622.  * &unary (typecast)unary sizeof(typecast)
  623.  * 
  624.  */
  625.     struct enode  **node;
  626. {
  627.     TYP            *tp, *tp1;
  628.     struct enode   *ep1, *ep2, *ep3;
  629.     int             flag, seen;
  630.     long            i;
  631.  
  632.     flag = 0;
  633.     switch (lastst) {
  634.     case autodec:
  635.         flag = 1;
  636.         /* fall through to common increment */
  637.     case autoinc:
  638.         getsym();
  639.         tp = unary(&ep1);
  640.         if (tp == NULL) {
  641.             error(ERR_IDEXPECT, NULL);
  642.             return NULL;
  643.         }
  644.         if (! lvalue(ep1)) 
  645.             error(ERR_LVALUE, NULL);
  646.         else {
  647.             if (tp->type == bt_pointer)
  648.                 ep2 = makenode(en_icon, (long) (tp->btp->size), NULL);
  649.             else
  650.                 ep2 = makenode(en_icon, 1L, NULL);
  651.             ep2->constflag = 1;
  652.  
  653.             switch (tp->type) {
  654.             case bt_float:
  655.                 ep3 = ep1;
  656.                 ep2 = makenode( en_clf, ep2, NULL );
  657.                 ep1 = makenode(flag ? en_fsubs : en_fadds, ep1, ep2);
  658.                 ep1 = makenode( en_assign, ep3, ep1 );
  659.                 break;
  660.             case bt_double:
  661.                 ep3 = ep1;
  662.                 ep2 = makenode( en_cld, ep2, NULL );
  663.                 ep1 = makenode(flag ? en_fsubd : en_faddd, ep1, ep2);
  664.                 ep1 = makenode( en_assign, ep3, ep1 );
  665.                 break;
  666.             default:
  667.                 ep1 = makenode(flag ? en_assub : en_asadd, ep1, ep2);
  668.                 break;
  669.             }
  670.         }
  671.         break;
  672.     case minus:
  673.         getsym();
  674.         tp = unary(&ep1);
  675.         if (tp == NULL) {
  676.             error(ERR_IDEXPECT, NULL);
  677.             return NULL;
  678.         }
  679.         switch (tp->type) {
  680.         case bt_float:
  681.             ep1 = makenode(en_fnegs, ep1, NULL);
  682.             break;
  683.         case bt_double:
  684.             ep1 = makenode(en_fnegd, ep1, NULL);
  685.             break;
  686.         default:
  687.             ep1 = makenode(en_uminus, ep1, NULL);
  688.             break;
  689.         }
  690.         ep1->constflag = ep1->v.p[0]->constflag;
  691.         break;
  692.     case not:
  693.         getsym();
  694.         tp = unary(&ep1);
  695.         if (tp == NULL) {
  696.             error(ERR_IDEXPECT, NULL);
  697.             return NULL;
  698.         }
  699.         ep1 = makenode(en_not, ep1, NULL);
  700.         ep1->constflag = ep1->v.p[0]->constflag;
  701.         break;
  702.     case compl:
  703.         getsym();
  704.         tp = unary(&ep1);
  705.         if (tp == NULL) {
  706.             error(ERR_IDEXPECT, NULL);
  707.             return NULL;
  708.         }
  709.         ep1 = makenode(en_compl, ep1, NULL);
  710.         ep1->constflag = ep1->v.p[0]->constflag;
  711.         break;
  712.     case star:
  713.         getsym();
  714.         tp = unary(&ep1);
  715.         if (tp == NULL) {
  716.             error(ERR_IDEXPECT, NULL);
  717.             return NULL;
  718.         }
  719.         if (tp->btp == NULL)
  720.             error(ERR_DEREF, NULL);
  721.         else
  722.             tp = tp->btp;
  723.         if (tp->val_flag == 0)
  724.             tp = deref(&ep1, tp);
  725.         break;
  726.     case and:
  727.         getsym();
  728.         tp = unary(&ep1);
  729.         if (tp == NULL) {
  730.             error(ERR_IDEXPECT, NULL);
  731.             return NULL;
  732.         }
  733.         if (lvalue(ep1))
  734.             ep1 = ep1->v.p[0];
  735.         tp1 = (TYP *) xalloc(sizeof(TYP));
  736.         tp1->size = 4;
  737.         tp1->type = bt_pointer;
  738.         tp1->btp = tp;
  739.         tp1->val_flag = 0;
  740.         tp1->lst.head = NULL;
  741.         tp1->sname = NULL;
  742.         tp = tp1;
  743.         break;
  744.     case kw_defined:
  745.         ep1 = makenode(en_icon, (long) dodefined(), NULL);
  746.         ep1->constflag = 1;
  747.         tp = &stdint;
  748.         getsym();
  749.         break;
  750.     case kw_sizeof:
  751.         getsym();
  752.         if (seen = (lastst == openpa))
  753.             needpunc(openpa);
  754.         if (castbegin(lastst)) {
  755.             decl(NULL);
  756.             decl1();
  757.             if (head != NULL)
  758.                 ep1 = makenode(en_icon, (long) (head->size), NULL);
  759.             else {
  760.                 error(ERR_IDEXPECT, NULL);
  761.                 ep1 = makenode(en_icon, 1L, NULL);
  762.             }
  763.         }
  764.         else {
  765.             head = exprnc(&ep2);
  766.             if (head != NULL)
  767.                 ep1 = makenode(en_icon, (long) (head->size), NULL);
  768.             else {
  769.                 error(ERR_IDEXPECT, NULL);
  770.                 ep1 = makenode(en_icon, 1L, NULL);
  771.             }
  772.         }
  773.         ep1->constflag = 1;
  774.         tp = &stdint;
  775.         if (seen)
  776.             needpunc(closepa);
  777.         break;
  778.  
  779.     default:
  780.         tp = primary(&ep1);
  781.         if (tp != NULL) {
  782.             if (tp->type == bt_pointer)
  783.                 i = tp->btp->size;
  784.             else
  785.                 i = 1;
  786.             if (lastst == autoinc) {
  787.                 if (lvalue(ep1)) {
  788.                     ep2 = makenode( en_icon, (long) i, NULL );
  789.                     switch (tp->type) {
  790.                     case bt_float:
  791.                         ep2 = makenode( en_clf, ep2, NULL );
  792.                         ep1 = makenode( en_faincs, ep1, ep2 );
  793.                         break;
  794.                     case bt_double:
  795.                         ep2 = makenode( en_cld, ep2, NULL );
  796.                         ep1 = makenode( en_faincd, ep1, ep2 );
  797.                         break;
  798.                     default:
  799.                         ep1 = makenode( en_ainc, ep1, ep2 );
  800.                         break;
  801.                     }
  802.                 }
  803.                 else
  804.                     error(ERR_LVALUE, NULL);
  805.                 getsym();
  806.             }
  807.             else if (lastst == autodec) {
  808.                 if (lvalue(ep1)) {
  809.                     ep2 = makenode( en_icon, (long) i, NULL );
  810.                     switch (tp->type) {
  811.                     case bt_float:
  812.                         ep2 = makenode( en_uminus, ep2, NULL );
  813.                         ep2 = makenode( en_clf, ep2, NULL );
  814.                         ep1 = makenode( en_faincs, ep1, ep2 );
  815.                         break;
  816.                     case bt_double:
  817.                         ep2 = makenode( en_uminus, ep2, NULL );
  818.                         ep2 = makenode( en_cld, ep2, NULL );
  819.                         ep1 = makenode( en_faincd, ep1, ep2 );
  820.                         break;
  821.                     default:
  822.                         ep1 = makenode( en_adec, ep1, ep2 );
  823.                         break;
  824.                     }
  825.                 }
  826.                 else
  827.                     error(ERR_LVALUE, NULL);
  828.                 getsym();
  829.             }
  830.         }
  831.         break;
  832.     }
  833.     *node = ep1;
  834.     return tp;
  835. }
  836.  
  837. int
  838. isscalar(tp)
  839.  
  840. /*
  841.  * this function returns true when the type of the argument is one of char,
  842.  * short, unsigned, or long.
  843.  */
  844.     TYP            *tp;
  845. {
  846.     return
  847.         (tp->type == bt_char || tp->type == bt_uchar ||
  848.          tp->type == bt_short || tp->type == bt_ushort ||
  849.          tp->type == bt_long ||
  850.          tp->type == bt_unsigned);
  851. }
  852.  
  853. TYP            *
  854. multops(node)
  855.  
  856. /*
  857.  * multops parses the multiply priority operators. the syntax of this group
  858.  * is:
  859.  * 
  860.  * unary multop * unary multop / unary multop % unary
  861.  */
  862.     struct enode  **node;
  863. {
  864.     struct enode   *ep1, *ep2;
  865.     TYP            *tp1, *tp2;
  866.     enum e_sym      oper;
  867.  
  868.     tp1 = unary(&ep1);
  869.     if (tp1 == NULL)
  870.         return NULL;
  871.     while (lastst == star || lastst == divide || lastst == modop) {
  872.         oper = lastst;
  873.         getsym();   /* move on to next unary op */
  874.         tp2 = unary(&ep2);
  875.         if (tp2 == NULL) {
  876.             error(ERR_IDEXPECT, NULL);
  877.             *node = ep1;
  878.             return tp1;
  879.         }
  880.         tp1 = forcefit(&ep1, tp1, &ep2, tp2);
  881.         switch (oper) {
  882.         case star:
  883.             switch (tp1->type) {
  884.             case bt_float:
  885.                 ep1 = makenode(en_fmuls, ep1, ep2);
  886.                 break;
  887.             case bt_double:
  888.                 ep1 = makenode(en_fmuld, ep1, ep2);
  889.                 break;
  890.             case bt_unsigned:
  891.             case bt_uchar:
  892.             case bt_ushort:
  893.                 ep1 = makenode(en_umul, ep1, ep2);
  894.                 ep1->signedflag = 0;
  895.                 break;
  896.             default:
  897.                 ep1 = makenode(en_mul, ep1, ep2);
  898.                 break;
  899.             }
  900.             break;
  901.         case divide:
  902.             switch (tp1->type) {
  903.             case bt_float:
  904.                 ep1 = makenode(en_fdivs, ep1, ep2);
  905.                 break;
  906.             case bt_double:
  907.                 ep1 = makenode(en_fdivd, ep1, ep2);
  908.                 break;
  909.             case bt_unsigned:
  910.             case bt_uchar:
  911.             case bt_ushort:
  912.                 ep1 = makenode(en_udiv, ep1, ep2);
  913.                 ep1->signedflag = 0;
  914.                 break;
  915.             default:
  916.                 ep1 = makenode(en_div, ep1, ep2);
  917.                 break;
  918.             }
  919.             break;
  920.         case modop:
  921.             switch (tp1->type) {
  922.             case bt_float:
  923.                 ep1 = makenode(en_fmods, ep1, ep2);
  924.                 break;
  925.             case bt_double:
  926.                 ep1 = makenode(en_fmodd, ep1, ep2);
  927.                 break;
  928.             case bt_unsigned:
  929.             case bt_uchar:
  930.             case bt_ushort:
  931.                 ep1 = makenode(en_umod, ep1, ep2);
  932.                 ep1->signedflag = 0;
  933.                 break;
  934.             default:
  935.                 ep1 = makenode(en_mod, ep1, ep2);
  936.                 break;
  937.             }
  938.             break;
  939.         }
  940.         ep1->constflag = ep1->v.p[0]->constflag &&
  941.             ep1->v.p[1]->constflag;
  942.     }
  943.     *node = ep1;
  944.     return tp1;
  945. }
  946.  
  947. TYP            *
  948. addops(node)
  949.  
  950. /*
  951.  * addops handles the addition and subtraction operators.
  952.  */
  953.     struct enode  **node;
  954. {
  955.     struct enode   *ep1, *ep2, *ep3;
  956.     TYP            *tp1, *tp2;
  957.     int             oper;
  958.  
  959.     tp1 = multops(&ep1);
  960.     if (tp1 == NULL)
  961.         return NULL;
  962.     while (lastst == plus || lastst == minus) {
  963.         oper = (lastst == plus ? 1 : 0);
  964.         getsym();
  965.         tp2 = multops(&ep2);
  966.         if (tp2 == NULL) {
  967.             error(ERR_IDEXPECT, NULL);
  968.             *node = ep1;
  969.             return tp1;
  970.         }
  971.         if (tp1->type == bt_pointer) {
  972.             if (tp2->type != bt_pointer) {
  973.                 tp2 = forcefit(NULL, &stdint, &ep2, tp2);
  974.                 ep3 = makenode(en_icon, (long) (tp1->btp->size), NULL);
  975.                 ep3->constflag = 1;
  976.                 ep2 = makenode(en_mul, ep3, ep2);
  977.                 ep2->constflag = ep2->v.p[1]->constflag;
  978.             }
  979.         }
  980.         else if (tp2->type == bt_pointer) {
  981.             if (tp1->type != bt_pointer) {
  982.                 tp1 = forcefit(NULL, &stdint, &ep1, tp1);
  983.                 ep3 = makenode(en_icon, (long) (tp2->btp->size), NULL);
  984.                 ep3->constflag = 1;
  985.                 ep1 = makenode(en_mul, ep3, ep1);
  986.                 ep1->constflag = ep1->v.p[1]->constflag;
  987.             }
  988.         }
  989.         tp1 = forcefit(&ep1, tp1, &ep2, tp2);
  990.         switch (tp1->type) {
  991.         case bt_pointer:
  992.             ep1 = makenode(oper ? en_add : en_sub, ep1, ep2);
  993.             if (tp2->type == bt_pointer && !oper) {
  994.                 ep3 = makenode(en_icon, (long) (tp1->btp->size), NULL);
  995.                 ep3->constflag = 1;
  996.                 ep1 = makenode(en_div, ep1, ep3);
  997.                 tp1 = &stdint;
  998.             }
  999.             break;
  1000.         case bt_float:
  1001.             ep1 = makenode(oper ? en_fadds : en_fsubs, ep1, ep2);
  1002.             break;
  1003.         case bt_double:
  1004.             ep1 = makenode(oper ? en_faddd : en_fsubd, ep1, ep2);
  1005.             break;
  1006.         default:
  1007.             ep1 = makenode(oper ? en_add : en_sub, ep1, ep2);
  1008.             break;
  1009.         }
  1010.         ep1->constflag = ep1->v.p[0]->constflag &&
  1011.             ep1->v.p[1]->constflag;
  1012.     }
  1013.     *node = ep1;
  1014.     return tp1;
  1015. }
  1016.  
  1017. TYP            *
  1018. shiftop(node)
  1019.  
  1020. /*
  1021.  * shiftop handles the shift operators << and >>.
  1022.  */
  1023.     struct enode  **node;
  1024. {
  1025.     struct enode   *ep1, *ep2;
  1026.     TYP            *tp1, *tp2;
  1027.     int             oper;
  1028.  
  1029.     tp1 = addops(&ep1);
  1030.     if (tp1 == NULL)
  1031.         return NULL;
  1032.     while (lastst == lshift || lastst == rshift) {
  1033.         oper = (lastst == lshift);
  1034.         getsym();
  1035.         tp2 = addops(&ep2);
  1036.         if (tp2 == NULL)
  1037.             error(ERR_IDEXPECT, NULL);
  1038.         else {
  1039.             tp1 = forcefit(&ep1, tp1, &ep2, tp2);
  1040.             ep1 = makenode(oper ? en_lsh : en_rsh, ep1, ep2);
  1041.             ep1->constflag = ep1->v.p[0]->constflag &&
  1042.                 ep1->v.p[1]->constflag;
  1043.         }
  1044.     }
  1045.     *node = ep1;
  1046.     return tp1;
  1047. }
  1048.  
  1049. TYP            *
  1050. relation(node)
  1051.  
  1052. /*
  1053.  * relation handles the relational operators < <= > and >=.
  1054.  */
  1055.     struct enode  **node;
  1056. {
  1057.     struct enode   *ep1, *ep2;
  1058.     TYP            *tp1, *tp2;
  1059.     enum e_node     nt;
  1060.  
  1061.     tp1 = shiftop(&ep1);
  1062.     if (tp1 == NULL)
  1063.         return NULL;
  1064.     for (;;) {
  1065.         switch (lastst) {
  1066.  
  1067.         case lt:
  1068.             switch (tp1->type) {
  1069.             case bt_unsigned:
  1070.             case bt_uchar:
  1071.             case bt_ushort:
  1072.                 nt = en_ult;
  1073.                 break;
  1074.             default:
  1075.                 nt = en_lt;
  1076.             }
  1077.             break;
  1078.         case gt:
  1079.             switch (tp1->type) {
  1080.             case bt_unsigned:
  1081.             case bt_uchar:
  1082.             case bt_ushort:
  1083.                 nt = en_ugt;
  1084.                 break;
  1085.             default:
  1086.                 nt = en_gt;
  1087.             }
  1088.             break;
  1089.         case leq:
  1090.             switch (tp1->type) {
  1091.             case bt_unsigned:
  1092.             case bt_uchar:
  1093.             case bt_ushort:
  1094.                 nt = en_ule;
  1095.                 break;
  1096.             default:
  1097.                 nt = en_le;
  1098.             }
  1099.             break;
  1100.         case geq:
  1101.             switch (tp1->type) {
  1102.             case bt_unsigned:
  1103.             case bt_uchar:
  1104.             case bt_ushort:
  1105.                 nt = en_uge;
  1106.                 break;
  1107.             default:
  1108.                 nt = en_ge;
  1109.             }
  1110.             break;
  1111.         default:
  1112.             goto fini;
  1113.         }
  1114.         getsym();
  1115.         tp2 = shiftop(&ep2);
  1116.         if (tp2 == NULL)
  1117.             error(ERR_IDEXPECT, NULL);
  1118.         else {
  1119.             tp1 = forcefit(&ep1, tp1, &ep2, tp2);
  1120.             ep1 = makenode(nt, ep1, ep2);
  1121.             ep1->constflag = ep1->v.p[0]->constflag &&
  1122.                 ep1->v.p[1]->constflag;
  1123.             if (tp1->type == bt_double || tp1->type == bt_float)
  1124.                 tp1 = &stdint;
  1125.         }
  1126.     }
  1127. fini:
  1128.     *node = ep1;
  1129.     return tp1;
  1130. }
  1131.  
  1132. TYP            *
  1133. equalops(node)
  1134.  
  1135. /*
  1136.  * equalops handles the equality and inequality operators.
  1137.  */
  1138.     struct enode  **node;
  1139. {
  1140.     struct enode   *ep1, *ep2;
  1141.     TYP            *tp1, *tp2;
  1142.     enum e_sym      lastoper;
  1143.  
  1144.     tp1 = relation(&ep1);
  1145.     if (tp1 == NULL)
  1146.         return NULL;
  1147.     while (lastst == eq || lastst == neq) {
  1148.         lastoper = lastst;
  1149.         getsym();
  1150.         tp2 = relation(&ep2);
  1151.         if (tp2 == NULL)
  1152.             error(ERR_IDEXPECT, NULL);
  1153.         else {
  1154.             tp1 = forcefit(&ep1, tp1, &ep2, tp2);
  1155.             ep1 = makenode(lastoper == eq ? en_eq : en_ne, ep1, ep2);
  1156.             ep1->constflag = ep1->v.p[0]->constflag &&
  1157.                 ep1->v.p[1]->constflag;
  1158.             tp1 = &stdint;
  1159.         }
  1160.     }
  1161.     *node = ep1;
  1162.     return tp1;
  1163. }
  1164.  
  1165. TYP *
  1166. binop(node, xfunc, nt, sy)
  1167.  
  1168. /*
  1169.  * binop is a common routine to handle all of the legwork and error checking
  1170.  * for bitand, bitor, bitxor, andop, and orop.
  1171.  */
  1172. struct enode  **node;
  1173. TYP            *(*xfunc) ();
  1174. enum e_node     nt;
  1175. enum e_sym      sy;
  1176.  
  1177. {
  1178.     struct enode   *ep1, *ep2;
  1179.     TYP            *tp1, *tp2;
  1180.  
  1181.     tp1 = (*xfunc) (&ep1);
  1182.     if (tp1 == NULL)
  1183.         return NULL;
  1184.     while (lastst == sy) {
  1185.         getsym();
  1186.         tp2 = (*xfunc) (&ep2);
  1187.         if (tp2 == NULL)
  1188.             error(ERR_IDEXPECT, NULL);
  1189.         else {
  1190.             if ( sy != land && sy != lor )
  1191.                 tp1 = forcefit(&ep1, tp1, &ep2, tp2);
  1192.             ep1 = makenode(nt, ep1, ep2);
  1193.             ep1->constflag = ep1->v.p[0]->constflag &&
  1194.                 ep1->v.p[1]->constflag;
  1195.         }
  1196.     }
  1197.     *node = ep1;
  1198.     return tp1;
  1199. }
  1200.  
  1201. TYP            *
  1202. bitand(node)
  1203.  
  1204. /*
  1205.  * the bitwise and operator...
  1206.  */
  1207.     struct enode  **node;
  1208. {
  1209.     return binop(node, equalops, en_and, and);
  1210. }
  1211.  
  1212. TYP            *
  1213. bitxor(node)
  1214.     struct enode  **node;
  1215. {
  1216.     return binop(node, bitand, en_xor, uparrow);
  1217. }
  1218.  
  1219. TYP            *
  1220. bitor(node)
  1221.     struct enode  **node;
  1222. {
  1223.     return binop(node, bitxor, en_or, or);
  1224. }
  1225.  
  1226. TYP            *
  1227. andop(node)
  1228.     struct enode  **node;
  1229. {
  1230.     return binop(node, bitor, en_land, land);
  1231. }
  1232.  
  1233. TYP            *
  1234. orop(node)
  1235.     struct enode  **node;
  1236. {
  1237.     return binop(node, andop, en_lor, lor);
  1238. }
  1239.  
  1240. TYP            *
  1241. conditional(node)
  1242.  
  1243. /*
  1244.  * this routine processes the hook operator.
  1245.  */
  1246.     struct enode  **node;
  1247. {
  1248.     TYP            *tp1, *tp2, *tp3;
  1249.     struct enode   *ep1, *ep2, *ep3;
  1250.  
  1251.     tp1 = orop(&ep1);   /* get condition */
  1252.     if (tp1 == NULL)
  1253.         return NULL;
  1254.     if (lastst == hook) {
  1255.         getsym();
  1256.         if ((tp2 = expression(&ep2)) == NULL) {
  1257.             error(ERR_IDEXPECT, NULL);
  1258.             goto cexit;
  1259.         }
  1260.         needpunc(colon);
  1261.         if ((tp3 = conditional(&ep3)) == NULL) {
  1262.             error(ERR_IDEXPECT, NULL);
  1263.             goto cexit;
  1264.         }
  1265.         switch (tp2->type) {
  1266.         case bt_float:
  1267.         case bt_double:
  1268.         case bt_struct:
  1269.         case bt_union:
  1270.             break;
  1271.         default:
  1272.             tp2 = forcefit(NULL, &stdint, &ep2, tp2);
  1273.             break;
  1274.         }
  1275.  
  1276.         switch (tp3->type) {
  1277.         case bt_float:
  1278.         case bt_double:
  1279.         case bt_struct:
  1280.         case bt_union:
  1281.             break;
  1282.         default:
  1283.             tp3 = forcefit(NULL, &stdint, &ep3, tp3);
  1284.             break;
  1285.         }
  1286.  
  1287.         tp1 = forcefit(&ep2, tp2, &ep3, tp3);
  1288.         ep2 = makenode(en_void, ep2, ep3);
  1289.         ep1 = makenode(en_cond, ep1, ep2);
  1290.     }
  1291. cexit:
  1292.     *node = ep1;
  1293.     return tp1;
  1294. }
  1295.  
  1296. TYP            *
  1297. asnop(node)
  1298.  
  1299. /*
  1300.  * asnop handles the assignment operators. currently only the simple
  1301.  * assignment is implemented.
  1302.  */
  1303.     struct enode  **node;
  1304. {
  1305.     struct enode   *ep1, *ep2, *ep3;
  1306.     TYP            *tp1, *tp2;
  1307.     enum e_node     op, op2;
  1308.  
  1309.     tp1 = conditional(&ep1);
  1310.     if (tp1 == NULL)
  1311.         return NULL;
  1312.     op2 = en_void;
  1313.     for (;;) {
  1314.         switch (lastst) {
  1315.         case assign:
  1316.             op = en_assign;
  1317.     ascomm:
  1318.             getsym();
  1319.             tp2 = asnop(&ep2);
  1320.     ascomm2:
  1321.             if (tp2 == NULL) {
  1322.                 error(ERR_LVALUE, NULL);
  1323.             }
  1324.             else if (tp1->type == bt_struct || tp1->type == bt_union) {
  1325.                 if (op != en_assign || tp1->type != tp2->type)
  1326.                     error(ERR_LVALUE, NULL);
  1327.                 else {
  1328.                     tp1 = deref(&ep1, tp1);
  1329.                     tp2 = deref(&ep2, tp2);
  1330.                     tp1 = asforcefit(&ep1, tp1, &ep2, tp2);
  1331.                     ep1 = makenode(op, ep1, ep2);
  1332.                 }
  1333.             }
  1334.             else if (!lvalue(ep1)) {
  1335.                 error(ERR_LVALUE, NULL);
  1336.             }
  1337.             else {
  1338.                 if (op2 == en_void) {
  1339.                     tp1 = asforcefit(&ep1, tp1, &ep2, tp2);
  1340.                     ep1 = makenode(op, ep1, ep2);
  1341.                 }
  1342.                 else {
  1343.                     tp1 = asforcefit(&ep1, tp1, &ep2, tp2);
  1344.                     ep3 = makenode(op2, ep1, ep2);
  1345.                     ep1 = makenode(en_assign, ep1, ep3);
  1346.                 }
  1347.             }
  1348.             break;
  1349.         case asplus:
  1350.             switch (tp1->type) {
  1351.             case bt_float:
  1352.                 op = en_assign;
  1353.                 op2 = en_fadds;
  1354.                 break;
  1355.             case bt_double:
  1356.                 op = en_assign;
  1357.                 op2 = en_faddd;
  1358.                 break;
  1359.             default:
  1360.                 op = en_asadd;
  1361.                 break;
  1362.             }
  1363.     ascomm3:
  1364.             getsym();
  1365.             tp2 = asnop(&ep2);
  1366.             if (tp1->type == bt_pointer) {
  1367.                 ep3 = makenode(en_icon, (long) (tp1->btp->size), NULL);
  1368.                 ep2 = makenode(en_mul, ep2, ep3);
  1369.             }
  1370.             goto ascomm2;
  1371.         case asminus:
  1372.             switch (tp1->type) {
  1373.             case bt_float:
  1374.                 op = en_assign;
  1375.                 op2 = en_fsubs;
  1376.                 break;
  1377.             case bt_double:
  1378.                 op = en_assign;
  1379.                 op2 = en_fsubd;
  1380.                 break;
  1381.             default:
  1382.                 op = en_assub;
  1383.                 break;
  1384.             }
  1385.             goto ascomm3;
  1386.         case astimes:
  1387.             switch (tp1->type) {
  1388.             case bt_float:
  1389.                 op = en_assign;
  1390.                 op2 = en_fmuls;
  1391.                 break;
  1392.             case bt_double:
  1393.                 op = en_assign;
  1394.                 op2 = en_fmuld;
  1395.                 break;
  1396.             case bt_unsigned:
  1397.             case bt_uchar:
  1398.             case bt_ushort:
  1399.                 op = en_asumul;
  1400.                 break;
  1401.             default:
  1402.                 op = en_asmul;
  1403.                 break;
  1404.             }
  1405.             goto ascomm;
  1406.         case asdivide:
  1407.             switch (tp1->type) {
  1408.             case bt_float:
  1409.                 op = en_assign;
  1410.                 op2 = en_fdivs;
  1411.                 break;
  1412.             case bt_double:
  1413.                 op = en_assign;
  1414.                 op2 = en_fdivd;
  1415.                 break;
  1416.             case bt_unsigned:
  1417.             case bt_uchar:
  1418.             case bt_ushort:
  1419.                 op = en_asudiv;
  1420.                 break;
  1421.             default:
  1422.                 op = en_asdiv;
  1423.                 break;
  1424.             }
  1425.             goto ascomm;
  1426.         case asmodop:
  1427.             switch (tp1->type) {
  1428.             case bt_float:
  1429.                 op = en_assign;
  1430.                 op2 = en_fmods;
  1431.                 break;
  1432.             case bt_double:
  1433.                 op = en_assign;
  1434.                 op2 = en_fmodd;
  1435.                 break;
  1436.             case bt_unsigned:
  1437.             case bt_uchar:
  1438.             case bt_ushort:
  1439.                 op = en_asumod;
  1440.                 break;
  1441.             default:
  1442.                 op = en_asmod;
  1443.                 break;
  1444.             }
  1445.             goto ascomm;
  1446.         case aslshift:
  1447.             op = en_aslsh;
  1448.             goto ascomm;
  1449.         case asrshift:
  1450.             op = en_asrsh;
  1451.             goto ascomm;
  1452.         case asand:
  1453.             op = en_asand;
  1454.             goto ascomm;
  1455.         case asor:
  1456.             op = en_asor;
  1457.             goto ascomm;
  1458.         case aseor:
  1459.             op = en_aseor;
  1460.             goto ascomm;
  1461.         default:
  1462.             goto asexit;
  1463.         }
  1464.     }
  1465. asexit:
  1466.     *node = ep1;
  1467.     return tp1;
  1468. }
  1469.  
  1470. TYP            *
  1471. exprnc(node)
  1472.  
  1473. /*
  1474.  * evaluate an expression where the comma operator is not legal.
  1475.  */
  1476.     struct enode  **node;
  1477. {
  1478.     TYP            *tp;
  1479.  
  1480.     tp = asnop(node);
  1481.     if (tp == NULL)
  1482.         *node = NULL;
  1483.     return tp;
  1484. }
  1485.  
  1486. TYP            *
  1487. commaop(node)
  1488.  
  1489. /*
  1490.  * evaluate the comma operator. comma operators are kept as void nodes.
  1491.  */
  1492.     struct enode  **node;
  1493. {
  1494.     TYP            *tp1;
  1495.     struct enode   *ep1, *ep2;
  1496.  
  1497.     tp1 = asnop(&ep1);
  1498.     if (tp1 == NULL)
  1499.         return NULL;
  1500.     if (lastst == comma) {
  1501.         getsym();
  1502.         tp1 = commaop(&ep2);
  1503.         if (tp1 == NULL) {
  1504.             error(ERR_IDEXPECT, NULL);
  1505.             goto coexit;
  1506.         }
  1507.         ep1 = makenode(en_void, ep1, ep2);
  1508.     }
  1509. coexit:
  1510.     *node = ep1;
  1511.     return tp1;
  1512. }
  1513.  
  1514. TYP            *
  1515. expression(node)
  1516.  
  1517. /*
  1518.  * evaluate an expression where all operators are legal.
  1519.  */
  1520.     struct enode  **node;
  1521. {
  1522.     TYP            *tp;
  1523.  
  1524.     tp = commaop(node);
  1525.     if (tp == NULL)
  1526.         *node = NULL;
  1527.     return tp;
  1528. }
  1529.